/// 启动页面
/// 
/// 应用启动时显示的欢迎页面
/// 延迟后自动跳转到首页
/// 
/// 作者: Fluttert Team
/// 日期: 2024

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../app/routes.dart';

/// 启动页组件
class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

/// 启动页状态类
class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    super.initState();
    // 页面初始化时开始导航
    _navigateToHome();
  }

  /// 导航到首页
  /// 
  /// 延迟2秒后跳转到首页
  /// 使用mounted检查确保组件仍然存在
  void _navigateToHome() async {
    await Future.delayed(const Duration(seconds: 2));
    // 检查组件是否仍然挂载，避免在已销毁的组件上操作
    if (mounted) {
      context.go(AppRoutes.home);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(
              Icons.flutter_dash,
              size: 100,
              color: Theme.of(context).colorScheme.primary,
            ),
            const SizedBox(height: 20),
            Text(
              'Fluttert',
              style: Theme.of(context).textTheme.headlineLarge,
            ),
          ],
        ),
      ),
    );
  }
}

